home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / drivers / mscdex / inst_cd / msrlec / rlea.asm < prev   
Encoding:
Assembly Source File  |  1992-10-27  |  11.3 KB  |  463 lines

  1.      page    ,132
  2. ;-----------------------------Module-Header-----------------------------;
  3. ; Module Name:  RLEA.ASM - helper routines for RLE stuff
  4. ;
  5. ; Created: Thu 27-Jun-1991
  6. ; Author:  Todd Laney [ToddLa]
  7. ;
  8. ; Copyright (c) 1991 Microsoft Corporation
  9. ;
  10. ; Exported Functions:   none
  11. ;
  12. ; Public Functions:     DecodeRle386
  13. ;
  14. ; Public Data:          none
  15. ;
  16. ; General Description:
  17. ;
  18. ; Restrictions:
  19. ;
  20. ; History:
  21. ;       Thu 15-Aug-1991 13:45:58 -by-  Todd Laney [ToddLa]
  22. ;       Created.
  23. ;
  24. ;-----------------------------------------------------------------------;
  25.  
  26.     .xlist
  27.     include cmacros.inc
  28.         include windows.inc
  29.         .list
  30.  
  31. RLE_ESCAPE  equ 0
  32. RLE_EOL     equ 0
  33. RLE_EOF     equ 1
  34. RLE_JMP     equ 2
  35.  
  36. ; The following structure should be used to access high and low
  37. ; words of a DWORD.  This means that "word ptr foo[2]" -> "foo.hi".
  38.  
  39. LONG    struc
  40. lo    dw    ?
  41. hi    dw    ?
  42. LONG    ends
  43.  
  44. FARPOINTER    struc
  45. off    dw    ?
  46. sel    dw    ?
  47. FARPOINTER      ends
  48.  
  49. wptr    equ     <word ptr>
  50. bptr    equ     <byte ptr>
  51.  
  52. min_ax  macro   REG
  53.         sub     ax,REG
  54.     cwd
  55.     and    ax,dx
  56.         add     ax,REG
  57.     endm
  58.  
  59. max_ax  macro   REG
  60.         sub     ax,REG
  61.     cwd
  62.     not    dx
  63.         and     ax,dx
  64.         add     ax,REG
  65.     endm
  66.  
  67. ; -------------------------------------------------------
  68. ;        DATA SEGMENT DECLARATIONS
  69. ; -------------------------------------------------------
  70.  
  71. sBegin  Data
  72.  
  73. sEnd  Data
  74.  
  75. ; -------------------------------------------------------
  76. ;               CODE SEGMENT DECLARATIONS
  77. ; -------------------------------------------------------
  78.  
  79. ifndef SEGNAME
  80.     SEGNAME equ <_TEXT>
  81. endif
  82.  
  83. createSeg %SEGNAME, CodeSeg, word, public, CODE
  84.  
  85. sBegin  CodeSeg
  86.         assumes cs,CodeSeg
  87.         assumes ds,nothing
  88.         assumes es,nothing
  89.  
  90. ;---------------------------Macro---------------------------------------;
  91. ; ReadRLE
  92. ;
  93. ;   read a WORD from rle data
  94. ;
  95. ; Entry:
  96. ;    DS:ESI --> rle data
  97. ; Returns:
  98. ;    AX - word at DS:[ESI]
  99. ;    DS:ESI advanced
  100. ; History:
  101. ;       Wed 04-Jan-1990 13:45:58 -by-  Todd Laney [ToddLa]
  102. ;    Created.
  103. ;-----------------------------------------------------------------------;
  104. ReadRLE macro
  105.     lods    wptr ds:[esi]
  106.         endm
  107.  
  108. ;---------------------------Public-Routine------------------------------;
  109. ; DecodeRle386
  110. ;
  111. ;   copy a rle bitmap to a DIB
  112. ;
  113. ; Entry:
  114. ;       pBits       - pointer to rle bits
  115. ; Returns:
  116. ;       none
  117. ; Error Returns:
  118. ;    None
  119. ; Registers Preserved:
  120. ;       BP,DS,SI,DI
  121. ; Registers Destroyed:
  122. ;       AX,BX,CX,DX,FLAGS
  123. ; Calls:
  124. ;    INT 10h
  125. ; History:
  126. ;
  127. ;       Wed 04-Jan-1990 13:45:58 -by-  Todd Laney [ToddLa]
  128. ;    Created.
  129. ;-----------------------------------------------------------------------;
  130.     assumes ds,nothing
  131.         assumes es,nothing
  132.  
  133. cProc   DecodeRle386, <NEAR, PASCAL, PUBLIC>, <ds>
  134.     ParmD    lpbi
  135.     ParmD    pDest
  136.     ParmD    pBits
  137. cBegin
  138. .386
  139.     push    edi
  140.     push    esi
  141.  
  142.         xor     edi,edi
  143.         xor     esi,esi
  144.         xor     eax,eax
  145.         xor     ecx,ecx
  146.  
  147.     lds    si,lpbi
  148.  
  149.     mov    ax,wptr [si].biWidth
  150.     add    ax,3
  151.     and    ax,not 3
  152.     movzx    ebx,ax            ; ebx is next_scan
  153.  
  154.     les    di,pDest
  155.         lds     si,pBits
  156.         assumes ds,nothing
  157.  
  158. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  159. ; Start of RLE decoding
  160. ;
  161. ;   DS:SI   --> RLE bits
  162. ;   ES:DI   --> screen output (points to start of scan)
  163. ;
  164. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  165. RleBltStart:
  166.     mov    edx,edi         ; save start of scan
  167.  
  168. RleBltNext:
  169.         ReadRLE                     ; al=count ah=color
  170.  
  171.         or      al,al               ; is it a escape?
  172.         jz      RleBltEscape
  173.  
  174. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  175. ; We have found a encoded run (al != 0)
  176. ;
  177. ;   al - run length
  178. ;   ah - run color
  179. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  180. RleBltEncodedRun:
  181.         mov     cl,al
  182.     mov    al,ah
  183.  
  184.     shr    cx,1
  185.     rep    stos wptr es:[edi]
  186.     adc    cl,cl
  187.     rep    stos bptr es:[edi]
  188.  
  189.         jmp     short RleBltNext
  190.  
  191. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  192. ; We have found a RLE escape code (al=0)
  193. ; Possibilities are:
  194. ;       . End of Line            -  ah = 0
  195. ;       . End of RLE             -  ah = 1
  196. ;       . Delta                  -  ah = 2
  197. ;       . Unencoded run          -  ah = 3 or more
  198. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  199. RleBltEscape:
  200.         cmp     ah,al
  201.         je      RleBltEOL
  202.  
  203.         inc     al
  204.         cmp     ah,al
  205.         je      RleBltEOF
  206.  
  207.         inc     al
  208.         cmp     ah,al
  209.         je      RleBltDelta
  210.         errn$   RleBltUnencodedRun
  211.  
  212. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  213. ; We have found a un-encoded run (ah >= 3)
  214. ;
  215. ;   ah          is pixel count
  216. ;   DS:SI   --> pixels
  217. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  218. RleBltUnencodedRun:
  219.     mov    cl,ah
  220.  
  221.     shr    cx,1
  222.     rep    movs wptr es:[edi], wptr ds:[esi]
  223.     adc    cl,cl
  224.         rep     movs bptr es:[edi], bptr ds:[esi]
  225.  
  226.     inc    esi              ; !!! re-align source
  227.     and    si,not 1
  228.     jmp    short RleBltNext
  229.  
  230. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  231. ; We have found a delta jump, the next two bytes contain the jump values
  232. ; note the the jump values are unsigned bytes, x first then y
  233. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  234. RleBltDelta:
  235.         ReadRLE                     ; al = deltaX, ah = deltaY
  236.  
  237.         or      ah,ah
  238.         jnz     RleBltDeltaXY
  239.  
  240. RleBltDeltaX:
  241.     add    edi,eax
  242.         jmp     short RleBltNext
  243.  
  244. RleBltDeltaXY:
  245.         add     edi,ebx
  246.         add     edx,ebx
  247.         dec     ah
  248.         jnz     RleBltDeltaXY
  249.  
  250.     add    edi,eax
  251.         jmp     short RleBltNext
  252.  
  253. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  254. ; We have found a end of line marker, point ES:DI to the begining of the
  255. ; next scan
  256. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  257. RleBltEOL:
  258.         mov     edi,edx             ; go back to start of scan
  259.         add     edi,ebx             ; advance to next scan
  260.         jmp     short RleBltStart   ; go get some more
  261.  
  262. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  263. ; We have found a end of rle marker, clean up and exit.
  264. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  265. RleBltEOF:
  266.         errn$   RleBltExit
  267.  
  268. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  269. RleBltExit:
  270.     pop    esi
  271.         pop     edi
  272. .286
  273. cEnd
  274.  
  275. ;---------------------------Macro---------------------------------------;
  276. ; ReadRle286
  277. ;
  278. ;   read a WORD from rle data
  279. ;
  280. ; Entry:
  281. ;       DS:SI --> rle data
  282. ; Returns:
  283. ;       AX - word at DS:[SI]
  284. ;       DS:SI advanced
  285. ; History:
  286. ;       Wed 04-Jan-1990 13:45:58 -by-  Todd Laney [ToddLa]
  287. ;    Created.
  288. ;-----------------------------------------------------------------------;
  289. ReadRle286 macro
  290.         lods    wptr ds:[si]
  291.         endm
  292.  
  293. ;---------------------------Public-Routine------------------------------;
  294. ; DecodeRle286
  295. ;
  296. ;   copy a rle bitmap to a DIB
  297. ;
  298. ; Entry:
  299. ;       pBits       - pointer to rle bits
  300. ; Returns:
  301. ;       none
  302. ; Error Returns:
  303. ;    None
  304. ; Registers Preserved:
  305. ;       BP,DS,SI,DI
  306. ; Registers Destroyed:
  307. ;       AX,BX,CX,DX,FLAGS
  308. ; Calls:
  309. ;    INT 10h
  310. ; History:
  311. ;
  312. ;       Wed 04-Jan-1990 13:45:58 -by-  Todd Laney [ToddLa]
  313. ;    Created.
  314. ;-----------------------------------------------------------------------;
  315.     assumes ds,nothing
  316.         assumes es,nothing
  317.  
  318. cProc   DecodeRle286, <NEAR, PASCAL, PUBLIC>, <ds>
  319.     ParmD    lpbi
  320.     ParmD    pDest
  321.     ParmD    pBits
  322. cBegin
  323.     push    di
  324.     push    si
  325.  
  326.         xor     di,di
  327.         xor     si,si
  328.         xor     ax,ax
  329.         xor     cx,cx
  330.  
  331.     lds    si,lpbi
  332.  
  333.     mov    ax,wptr [si].biWidth
  334.     add    ax,3
  335.     and    ax,not 3
  336.     mov    bx,ax            ; bx is next_scan
  337.  
  338.     les    di,pDest
  339.         lds     si,pBits
  340.         assumes ds,nothing
  341.  
  342. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  343. ; Start of RLE decoding
  344. ;
  345. ;   DS:SI   --> RLE bits
  346. ;   ES:DI   --> screen output (points to start of scan)
  347. ;
  348. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  349. Rle286Start:
  350.     mov    dx,di            ; save start of scan
  351.  
  352. Rle286Next:
  353.         ReadRLE286                  ; al=count ah=color
  354.  
  355.         or      al,al               ; is it a escape?
  356.         jz      Rle286Escape
  357.  
  358. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  359. ; We have found a encoded run (al != 0)
  360. ;
  361. ;   al - run length
  362. ;   ah - run color
  363. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  364. Rle286EncodedRun:
  365.         mov     cl,al
  366.     mov    al,ah
  367.  
  368.     shr    cx,1
  369.     rep    stos wptr es:[di]
  370.     adc    cl,cl
  371.     rep    stos bptr es:[di]
  372.  
  373.         jmp     short Rle286Next
  374.  
  375. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  376. ; We have found a RLE escape code (al=0)
  377. ; Possibilities are:
  378. ;       . End of Line            -  ah = 0
  379. ;       . End of RLE             -  ah = 1
  380. ;       . Delta                  -  ah = 2
  381. ;       . Unencoded run          -  ah = 3 or more
  382. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  383. Rle286Escape:
  384.         cmp     ah,al
  385.         je      Rle286EOL
  386.  
  387.         inc     al
  388.         cmp     ah,al
  389.         je      Rle286EOF
  390.  
  391.         inc     al
  392.         cmp     ah,al
  393.         je      Rle286Delta
  394.         errn$   Rle286UnencodedRun
  395.  
  396. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  397. ; We have found a un-encoded run (ah >= 3)
  398. ;
  399. ;   ah          is pixel count
  400. ;   DS:SI   --> pixels
  401. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  402. Rle286UnencodedRun:
  403.     mov    cl,ah
  404.  
  405.     shr    cx,1
  406.     rep    movs wptr es:[di], wptr ds:[si]
  407.     adc    cl,cl
  408.         rep     movs bptr es:[di], bptr ds:[si]
  409.  
  410.     inc    si              ; !!! re-align source
  411.     and    si,not 1
  412.         jmp     short Rle286Next
  413.  
  414. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  415. ; We have found a delta jump, the next two bytes contain the jump values
  416. ; note the the jump values are unsigned bytes, x first then y
  417. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  418. Rle286Delta:
  419.         ReadRLE286                  ; al = deltaX, ah = deltaY
  420.  
  421.         or      ah,ah
  422.         jnz     Rle286DeltaXY
  423.  
  424. Rle286DeltaX:
  425.     add    di,ax
  426.         jmp     short Rle286Next
  427.  
  428. Rle286DeltaXY:
  429.         add     di,bx
  430.         add     dx,bx
  431.         dec     ah
  432.         jnz     Rle286DeltaXY
  433.  
  434.     add    di,ax
  435.         jmp     short Rle286Next
  436.  
  437. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  438. ; We have found a end of line marker, point ES:DI to the begining of the
  439. ; next scan
  440. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  441. Rle286EOL:
  442.         mov     di,dx             ; go back to start of scan
  443.         add     di,bx             ; advance to next scan
  444.         jmp     short Rle286Start ; go get some more
  445.  
  446. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  447. ; We have found a end of rle marker, clean up and exit.
  448. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  449. Rle286EOF:
  450.         errn$   Rle286Exit
  451.  
  452. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  453. Rle286Exit:
  454.     pop    si
  455.     pop    di
  456. cEnd
  457.  
  458. sEnd
  459.  
  460. sEnd
  461.  
  462. end
  463.